package com.wanmait.wisdom.manage.controller;

import com.wanmait.wisdom.entity.Staff;
import com.wanmait.wisdom.manage.service.ManageStaffService;
import com.wanmait.wisdom.util.AjaxResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/manage")
public class ManageStaffController {
    @Resource
    private ManageStaffService manageStaffService;

    @GetMapping("/getStaffCount")
    public AjaxResult getStaffCount(){
        return AjaxResult.success(manageStaffService.getStaffCount());
    }

    @PostMapping("/saveOrUpdateStaff")
    public AjaxResult saveOrUpdateStaff(@RequestBody Staff staff,String officeId){
        if (staff.getId()==null){
            staff.setOfficeId(Integer.parseInt(officeId));
            System.out.println(staff);
            return AjaxResult.success(manageStaffService.insertStaff(staff));
        }else {
            System.out.println(staff);
            return AjaxResult.success(manageStaffService.updateStaff(staff));
        }
    }
    @GetMapping("/selectStaff")
    public AjaxResult selectStaff(Integer pageNum,Integer pageSize){
        if(pageNum==null){
            return AjaxResult.success(manageStaffService.list());
        }

        return AjaxResult.success(manageStaffService.selectAllStaff(pageNum,pageSize));
    }


    @PostMapping("/updateStaff")
    @ResponseBody
    public AjaxResult updateStaffInfo(@RequestBody Staff staff){
        System.out.println(staff.getId());
        if (staff.getId()==null){
        }else {
            manageStaffService.updateById(staff);
        }
        return AjaxResult.success();
    }

    @GetMapping("/selectStaffById")
    public AjaxResult selectStaffById(Staff staff){
        Staff staffInfo = manageStaffService.selectStaffById(staff);
        return AjaxResult.success(staffInfo);
    }

    @PostMapping("/changeStaffEnable")
    public AjaxResult changeStaffEnable(@RequestBody Staff staff){
        System.out.println(staff);
        return AjaxResult.success(manageStaffService.changeStaffEnable(staff));
    }

}
